package com.hotel.controller;

import com.hotel.common.AjaxResult;
import com.hotel.domain.service.RoomInfoService;
import com.hotel.pojo.RoomInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/roomInfo")
public class RoomInfoController {

    @Autowired
    private RoomInfoService roomInfoService;

    /**
     * 获取房间详细信息列表
     * @param roomInfo 房间详细信息对象
     * @param page 页码
     * @param perPage 每页的条数
     * @return AjaxResult
     */
    @GetMapping("/{page}/{perPage}")
    @ResponseBody
    public AjaxResult getRoomInfoList(RoomInfo roomInfo, @PathVariable("page") int page, @PathVariable("perPage") int perPage){
        return AjaxResult.queryAjax(roomInfoService.getRoomInfoList(roomInfo, page, perPage));
    }

    /**
     * 添加房间信息
     * @param roomInfo 房间信息对象
     * @return AjaxResult
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addRoomInfo(@RequestBody RoomInfo roomInfo){
        return AjaxResult.updateAjax(roomInfoService.addRoomInfo(roomInfo));
    }

    /**
     * 更新房间信息
     * @param roomInfo 房间信息对象
     * @return AjaxResult
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult updateRoomInfo(@RequestBody RoomInfo roomInfo){
        return AjaxResult.updateAjax(roomInfoService.updateRoomInfo(roomInfo));
    }

    /**
     * 逻辑删除房间信息
     * @param roomId 房间ID
     * @return AjaxResult
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult deleteRoomInfo(@RequestBody int roomId){
        RoomInfo roomInfo = new RoomInfo();
        roomInfo.setRoomId(roomId);
        roomInfo.setRoomDel(1);
        return AjaxResult.updateAjax(roomInfoService.updateRoomInfo(roomInfo));
    }

}
